package com.comeval.persistencia;

import com.comeval.modelo.Laboratorio;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author LUISA
 */
@Stateless
public class LaboratorioDAO implements ILaboratorioDAO {

    @PersistenceContext
    private EntityManager entityManager;
    
    @Override
    public void registrar(Laboratorio laboratorio) {
        try{
            entityManager.persist(laboratorio);
        }catch(RuntimeException e){
            throw e;
        }
        
    }

    @Override
    public void modificar(Laboratorio laboratorio) {
        try{
            entityManager.merge(laboratorio);
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public void eliminar(Laboratorio laboratorio) {
        try{
            entityManager.remove(laboratorio);
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public List<Laboratorio> consultar() {
        try{
            String jpql="select l from Laboratorio l";
            Query query=entityManager.createQuery(jpql);
            return query.getResultList();
        }catch(RuntimeException e){
            throw e;
        }
    }

    @Override
    public Laboratorio consultarPorNit(String nit) {
        try{
            return entityManager.find(Laboratorio.class, nit);
        }catch(RuntimeException e){
            throw e;
        }
    }

   
}
